<?php $this->fetch('public/head') ?>
<div class="layui-tab layui-tab-brief">
    <ul class="layui-tab-title">
        <li class="layui-this">导入信息列表</li>
        <li class=""><a href="<?php echo url('add') ?>">工资导入</a></li>
    </ul>
    <div class="layui-tab-content">
        <a href="<?php echo url('saveSalary') ?>"><button type="button" class="layui-btn">发送通知消息</button></a>
        <hr>
        <div class="layui-tab-item layui-show">
            <table id="dataList" lay-filter="dataList" class="layui-hide"></table>
        </div>
    </div>
</div>
<?php $this->fetch('public/script') ?>

<script>
    layui.use(['table'], function(){
        var table = layui.table
            ,form = layui.form;

        getLists();
        form.on('select(query)', function(data){
            $(data.elem).trigger('change',data.elem); //此处可让select支持change事件，trigger方法触发被选元素的指定事件类型。
        });
        //改变查询条件后重新获取列表数据
        $('.query').change(function () {
            getLists();
        });

        function getLists() {
            let params = HS.getParams('.query');
            //数据表格
            // let load_table = layer.load(0, {time: 30000});
            table.render({
                elem: '#dataList'
                , height:$(window).height()-155
                //, url: '<?php //echo url('getSalaryLists') ?>//' //数据接口
                // , method: 'post'
                // , where: params
                // , response: {
                //     countName: 'total' //数据总数的字段名称，默认：count
                // }
                , page: {
                    limit: 20
                    , limits: [20, 30, 50, 100]
                    , groups: 5
                    , layout: ['prev', 'page', 'next', 'limit', 'refresh', 'skip', 'count']
                } //开启分页
                // , toolbar: '<div><span class="fl">已选 <i class="checkedNum"></i> 条信息</span> ' +
                //             '<a class="layui-btn layui-btn-danger layui-btn-sm checkbox_delete">删除</a></div>'
                , defaultToolbar: ['filter']    //, 'print', 'exports'
                , cols: [[ //表头
                    // {type: 'checkbox',minWidth: 80}
                    {field: 'userid', title: 'ID',minWidth: 80}
                    ,{field: 'department', title: '部门',minWidth: 80}
                    ,{field: 'name', title: '姓名',minWidth: 80}
                    ,{field: 'time', title: '月份',minWidth: 80}
                    ,{field: 'jbgz', title: '基本工资',minWidth: 80}
                    ,{field: 'gl', title: '工龄',minWidth: 80}
                    ,{field: 'jb', title: '加班',minWidth: 80}
                    ,{field: 'zyb', title: '中夜班',minWidth: 80}
                    ,{field: 'bm', title: '保密',minWidth: 80}
                    ,{field: 'zl', title: '资历',minWidth: 80}
                    ,{field: 'gwf', title: '高温费',minWidth: 80}
                    ,{field: 'bt', title: '补贴',minWidth: 80}
                    ,{field: 'jn', title: '技能',minWidth: 80}
                    ,{field: 'tx', title: '通讯',minWidth: 80}
                    ,{field: 'ct', title: '车贴',minWidth: 80}
                    ,{field: 'bc', title: '补差',minWidth: 80}
                    ,{field: 'zwbt', title: '职务补贴',minWidth: 80}
                    ,{field: 'sjjt', title: '司机津贴',minWidth: 80}
                    ,{field: 'qt1', title: '其它1',minWidth: 80}
                    ,{field: 'gwgz', title: '岗位工资',minWidth: 80}
                    ,{field: 'ws', title: '卫生',minWidth: 80}
                    ,{field: 'jrf', title: '节日费',minWidth: 80}
                    ,{field: 'ds', title: '独生',minWidth: 80}
                    ,{field: 'yy', title: '营养',minWidth: 80}
                    ,{field: 'bt2', title: '补贴2',minWidth: 80}
                    ,{field: 'zf', title: '住房',minWidth: 80}
                    ,{field: 'khgz', title: '考核工资',minWidth: 80}
                    ,{field: 'yfgz', title: '应发工资',minWidth: 80}
                    ,{field: 'bj', title: '病假',minWidth: 80}
                    ,{field: 'sj', title: '事假',minWidth: 80}
                    ,{field: 'kg', title: '旷工',minWidth: 80}
                    ,{field: 'k1', title: '扣1',minWidth: 80}
                    ,{field: 'kqxj', title: '考勤小计',minWidth: 80}
                    ,{field: 'znjy', title: '子女教育',minWidth: 80}
                    ,{field: 'jxjy', title: '继续教育',minWidth: 80}
                    ,{field: 'zfdklx', title: '住房贷款利息',minWidth: 80}
                    ,{field: 'zfzj', title: '住房租金',minWidth: 80}
                    ,{field: 'sylr', title: '赡养老人',minWidth: 80}
                    ,{field: 'sb', title: '社保',minWidth: 80}
                    ,{field: 'zfgjj', title: '住房公积金',minWidth: 80}
					,{field: 'dg', title: '待工',minWidth: 80}
                    ,{field: 'djxj', title: '代缴小计',minWidth: 80}
                    ,{field: 'gh', title: '工会',minWidth: 80}
                    ,{field: 'gts', title: '个调税',minWidth: 80}
                    ,{field: 'sfje', title: '实发金额',minWidth: 80}


                    // ,{field: 'userid', title: 'ID'}


                ]]
                , text: {none: '暂无相关数据'}
                ,data:<?php echo json_encode(session('salaryData')) ?>
                ,skin: 'line' //表格风格
                ,even: true
                //, done: function (res, curr, count) {
                //    layer.close(load_table);
                //    $('.checkedNum').text('0');//刷新后清除选择数目
                //    $('.checkbox_delete').unbind("click").click(function () {   //多选删除
                //        let checkStatus = table.checkStatus('dataList')
                //            ,data = checkStatus.data//包含行信息的data二维
                //            ,ids=[];
                //        let num = data.length;
                //        if(num === 0)return layer.msg('请选择条目');
                //        $.each(data,function (k, v) {
                //            ids.push(v.id);
                //        });
                //        layer.confirm('确定删除所选信息吗', {icon: 3, title:'提示'}, function(index){
                //            let loading = layer.load(1);
                //            $.post('<?php //echo url('delete') ?>//',{ids:ids},function (res) {
                //                layer.close(loading);layer.msg(res.msg);
                //                if(res.code === 1){
                //                    layer.close(index);
                //                    table.reload('dataList',{page: {curr: 1 }});//多条删除后表格重载,//重新从第 1 页开始
                //                }
                //            });
                //        });
                //    })
                //}
            })
        }
        //监听复选框选择
        table.on('checkbox(dataList)', function(obj){
            let checkStatus = table.checkStatus('dataList')
                ,data = checkStatus.data;//包含行信息的data二维
            $('.checkedNum').text(data.length)
        });
        //监听工具条
        table.on('tool(dataList)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            //var tr = obj.tr; //获得当前行 tr 的DOM对象
            if(layEvent === 'edit'){ //编辑
                location.href = HS.U('<?php echo url('indexUser',['pid'=>input('pid')]) ?>',{time:data.time});
            } else if(layEvent === 'del'){ //删除
                layer.confirm('确定删除该信息吗', {icon: 3, title:'提示'}, function(index){
                    let loading = layer.load(1);
                    $.post('<?php echo url('delete') ?>',{id:data.id},function (data) {
                        layer.close(loading);layer.msg(data.msg);
                        if(data.code === 1){
                            layer.close(index);obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                        }
                    });
                });
            }else if(layEvent === 'view'){ //删除
                window.open(HS.U('/index/pageinfo/index',{id:data.id}));
            }
        });
        //显示/隐藏、置顶操作
        form.on('switch(checkbox)', function(obj){
            let index = layer.load(1),param={};
            param[this.name] = obj.elem.checked?1:0;param.id = this.value;
            $.post('<?php echo url('flag') ?>',param,function (data) {
                layer.close(index);layer.msg(data.msg);
                if(data.code === 0){
                    obj.elem.checked = !obj.elem.checked;form.render('checkbox');
                }
            });
        });
    });
</script>